<ul class="navigation">
  <li><%= link_to 'Home'.t, tag_wranglings_path %></li>
  <% for categ in Tag::TYPES do %>
  <li><%= link_to_unless_current categ, edit_tag_wrangling_path(categ) %></li>
  <%- end -%>
</ul>

<h2><%=h 'Wrangle'.t %> <%= @category %> <%=h 'Tags'.t %>
<% if !@tags.blank? %>
  <%- if @fandom %>
      in <%= @fandom.name %>
  <%- elsif @media %>
      in <%= @media.name %>
  <%- end -%>
<%- end -%>
</h2>

<%- if @fandoms %>
  <%- form_tag tag_wranglings_path, :id => 'wrangle-select-fandom' do -%>
    <p><%= hidden_field_tag(:id, @category) %>
    <p><%=h 'Select Fandom:'.t %> <%= select("fandom", 'fandom_id', @fandoms.collect {|f| [ f.name, f.id ] }, {:selected => @fandom ? @fandom.id : nil}) %></p>
    <p class="submit"><%= submit_tag "Wrangle".t %></p>
  <%- end -%>
<%- elsif @medias %>
  <%- form_tag tag_wranglings_path, :id => 'wrangle-select-media' do -%>
    <p><%= hidden_field_tag(:id, @category) %></p>
    <p><%=h 'Select Media:'.t %> <%= select("media", 'media_id', @medias.collect {|f| [ f.name, f.id ] }, {:selected => @media ? @media.id : nil}) %></p>
    <p class="submit"><%= submit_tag "Wrangle".t %></p>
  <%- end -%>
<%- end -%>

<% if !@tags.blank? %>

<hr />

  <%- form_tag tag_wranglings_path do -%>
    <p><%= hidden_field_tag(:id, @category) %></p>
    <%- if @fandom -%>
      <p><%= hidden_field_tag("fandom[fandom_id]", @fandom.id) %></p>
    <%- elsif @media -%>
      <p><%= hidden_field_tag("media[media_id]", @media.id) %></p>
    <%- end -%>
    
    <table>
	<caption><%=h 'Tags to be wrangled'.t %></caption>
	<thead>
	<tr>
        <th scope="col"><%=h 'Tag'.t %></th>
        <th scope="col"><%=h 'Count'.t %></th>
      <%- if logged_in_as_admin? %>
        <th scope="col"><%=h 'Banned'.t %></th>
      <%- end -%>
      <%- if @category == Rating::NAME %>
        <th scope="col"><%=h 'Adult'.t %></th>
      <%- end -%>
        <th scope="col"><%=h 'Canonical'.t %></th>
        <th scope="col"><%=h 'Synonym'.t %></th>
      </tr>
	</thead>
 <tbody>
    <%- @tags.each do |tag| %>
    <tr>
      <td><%= label :tag, tag.id, link_to_edit_tag(tag) %></td>
      <td><%= tag.taggings_count %></td>
      <%- if logged_in_as_admin? %>
        <td><%= check_box_tag("banned[]", tag.id, tag.banned, :id => "banned_#{tag.id}") %></td>
      <%- end -%>
      <%- if @category == Rating::NAME %>
        <td><%= check_box_tag("adult[]", tag.id, tag.adult, :id => "adult_#{tag.id}") %></td>
      <% end %>
      <td><%= check_box_tag("canonical[]", tag.id, tag.canonical, :id => "tag_#{tag.id}") %></td>
      <% unless tag.canonical %>
        <td>
          <%- if @fandom -%>
            <%= select("merger", tag.id, (tag.class.by_fandom(@fandom).canonical - [tag]).collect {|p| [ p.name, p.id ] }, { :include_blank => true, :selected => tag.merger.andand.id}) %>
          <%- elsif @media -%>
            <%= select("merger", tag.id, (tag.class.by_media(@media).canonical - [tag]).collect {|p| [ p.name, p.id ] }, { :include_blank => true, :selected => tag.merger.andand.id}) %>
          <%- elsif @ambiguity -%>
             <%= select("merger", tag.id, (tag.class.canonical - [tag]).collect {|p| [ p.name, p.id ] }, { :include_blank => true, :selected => tag.merger.andand.id}) %>
          <%- else -%>
             <%= select("merger", tag.id, (tag.class.no_parent.canonical - [tag]).collect {|p| [ p.name, p.id ] }, { :include_blank => true, :selected => tag.merger.andand.id}) %>
          <%- end -%>
        </td>
      <%- end -%>
    </tr>
    <%- end -%>
    <!-- end tags each do -->
    </tbody>
</table>
    <%- if logged_in_as_admin? && @category == Banned::NAME %>
      <p class="message"><%=h "Note, you cannot mass wrangle tags from this page, as you must individually wrangle which category it should be moved into when unbanned".t %></p>
    <%- elsif !@tags.blank? -%>
      <p class="submit"><%= submit_tag "Update all tags".t %></p>
    <%- end -%>
    
  <%- end -%>
  <!-- end form_tag -->
  
<%- end -%>

<%= tag_wrangler_footer %>